import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;


public class JHelloWorld {
    public static void main( String[] args ) {
        try {
            JFrame frame = new JFrame("Hello World");
            frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
            frame.setSize( 400, 400);
            frame.setVisible( true );
            
            JPanel panel = new JPanel();
            
            panel.add(new JLabel("Button:"));
            
            JButton button = new JButton("Send");
            
            final JLabel output = new JLabel();
            final JTextField textField = new JTextField(30);
            textField.addActionListener( new TextFieldListener(textField, output) );
            panel.add(textField);
            
            panel.add(button);
            button.addActionListener( new TextFieldListener( textField, output ) );
            
            frame.getContentPane().add(output, BorderLayout.SOUTH);
            
            
            frame.getContentPane().add(panel);
        }
        catch ( Throwable t ) {
            t.printStackTrace( System.err );
        }
    }
    
    static class TextFieldListener implements ActionListener {
    	private JTextField textField;
		private JLabel output;
    	
		TextFieldListener(JTextField textField, JLabel output) {
    		this.textField = textField;
    		this.output = output;
    	}
		@Override
		public void actionPerformed(ActionEvent e) {
			output.setText(textField.getText());
		}
    	
    }
}
